import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { ValidationPipe } from '@nestjs/common';
import { WINSTON_MODULE_NEST_PROVIDER } from 'nest-winston';
import helmet from 'helmet';

async function bootstrap() {
  const app = await NestFactory.create(AppModule);

  // 1 设置安全头
  app.use(helmet());

  // 2 测试环境开启 CORS
  if (process.env.NODE_ENV === 'development') {
    app.enableCors();
  }

  app.useGlobalPipes(new ValidationPipe({ transform: true, whitelist: true }));
  if (process.env.NODE_ENV === 'production') {
    app.useLogger(app.get(WINSTON_MODULE_NEST_PROVIDER));
  }
  app.enableCors();
  await app.listen(process.env.NEST_SERVER_PORT ?? 3000);
}
bootstrap();
